package kr.ac.ml.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ac.kr.ml.dao.ListDao;
import ac.kr.ml.vo.ContentVo;
import kr.ac.ml.mvc.Action;

public class JSonAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub

		System.out.println("JSonAction");
		
		
		ListDao dao = new ListDao();
		List<ContentVo> list = dao.getAddressList();

		int length = list.size();

		String jsonStr = "";
		response.setContentType("text/html; charset=utf-8");

		jsonStr += "{";
		jsonStr += "\"data\":[";

		for (int i = 0; i < length; i++) {
			jsonStr += "{";
			jsonStr += "\"empID\":\"" + list.get(i).getempID() + "\",";
			jsonStr += "\"deptID\":\"" + list.get(i).getdeptID() + "\",";
			jsonStr += "\"deptName\":\"" + list.get(i).getdeptName() + "\",";
			jsonStr += "\"posName\":\"" + list.get(i).getposName() + "\",";
			jsonStr += "\"userName\":\"" + list.get(i).getuserName() + "\",";
			jsonStr += "\"email\":\"" + list.get(i).getemail() + "\",";
			jsonStr += "\"hp\":\"" + list.get(i).gethp() + "\",";
			jsonStr += "\"empCode\":\"" + list.get(i).getempCode() + "\"";
			if (i < length - 1) {
				jsonStr += "},";
			} else
				jsonStr += "}";

		}
		jsonStr += "]";
		jsonStr += "}";

		// PrintWriter out = response.getWriter();
		// out.println(jsonStr);
		// out.println(1011);

		request.setAttribute("json",jsonStr);
	
	}

}
